package com.lrkj.waitress.controller;

import com.lrkj.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.waitress.domain.Repairs;
import com.lrkj.waitress.service.IRepairsService;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.common.core.page.TableDataInfo;

/**
 * 投诉建议Controller
 *
 * @author yajun_ren
 * @date 2021-07-22
 */
@Api(tags = "投诉建议")
@RestController
@RequestMapping("/waitress/repairs")
public class RepairsController extends BaseController
{
    @Autowired
    private IRepairsService repairsService;

    /**
     * 查询投诉建议列表
     */
    @ApiOperation(value = "查询投诉建议列表", notes = "查询投诉建议列表")
    @PreAuthorize("@ss.hasPermi('waitress:repairs:list')")
    @GetMapping("/list")
    public TableDataInfo list(Repairs repairs)
    {
        startPage();
        List<Repairs> list = repairsService.selectRepairsList(repairs);
        return getDataTable(list);
    }

    /**
     * 导出投诉建议列表
     */
	@ApiOperation(value = "导出投诉建议列表", notes = "导出投诉建议列表")
    @PreAuthorize("@ss.hasPermi('waitress:repairs:export')")
    @Log(title = "投诉建议", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Repairs repairs)
    {
        List<Repairs> list = repairsService.selectRepairsList(repairs);
        ExcelUtil<Repairs> util = new ExcelUtil<Repairs>(Repairs.class);
        return util.exportExcel(list, "投诉建议数据");
    }

    /**
     * 获取投诉建议详细信息
     */
	@ApiOperation(value = "获取投诉建议详细信息", notes = "获取投诉建议详细信息")
    @PreAuthorize("@ss.hasPermi('waitress:repairs:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(repairsService.selectRepairsById(id));
    }

    /**
     * 新增投诉建议
     */
	  @ApiOperation(value = "新增投诉建议", notes = "新增投诉建议")
    @PreAuthorize("@ss.hasPermi('waitress:repairs:add')")
    @Log(title = "投诉建议", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Repairs repairs)
    {
        repairs.setCreateBy(SecurityUtils.getUsername());
        return toAjax(repairsService.insertRepairs(repairs));
    }

    /**
     * 修改投诉建议
     */
	 @ApiOperation(value = "修改投诉建议", notes = "修改投诉建议")
    @PreAuthorize("@ss.hasPermi('waitress:repairs:edit')")
    @Log(title = "投诉建议", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Repairs repairs)
    {
        return toAjax(repairsService.updateRepairs(repairs));
    }

    /**
     * 删除投诉建议
     */
	 @ApiOperation(value = "删除投诉建议", notes = "删除投诉建议")
    @PreAuthorize("@ss.hasPermi('waitress:repairs:remove')")
    @Log(title = "投诉建议", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(repairsService.deleteRepairsByIds(ids));
    }
}
